// LSL script generated: RLV-New.Addons.DV_MAIN_Schock Distance.lslp Sun May  2 00:09:51 Westeuropäische Sommerzeit 2010
list gMenu = [];
list statesMenu = [0,0,0,0];
key ToucherID;
integer channel_dialog;
integer listen_id;
string msg;
list distance = ["2","5","10","15","20"];
displayMenu(){
    (gMenu = []);
    if ((llList2Integer(statesMenu,0) == 1)) (gMenu += "[x]Range");
    else  (gMenu += "[ ]Range");
    (gMenu += "Back");
    (gMenu += distance);
    (msg = "Pick one");
    (channel_dialog = (-1 * ((integer)("0x" + llGetSubString(((string)llGetKey()),-5,-1)))));
    (listen_id = llListen(channel_dialog,"",NULL_KEY,""));
    llDialog(ToucherID,msg,gMenu,channel_dialog);
}

RequestPerms(){
    if (llGetAttached()) {
        llRequestPermissions(llGetOwner(),16);
    }
}

llLRP(integer element_new,integer placeinlist){
    (statesMenu = llListReplaceList(statesMenu,[element_new],placeinlist,placeinlist));
}

default {

    state_entry() {
        RequestPerms();
    }

     listen(integer channel,string name,key id,string message) {
        if ((channel == channel_dialog)) {
            llListenRemove(listen_id);
            if ((message == "[x]Range")) {
                llLRP(0,0);
                llSensorRepeat("",ToucherID,1,60.0,3.14159274,20.0);
                displayMenu();
            }
            else  if ((message == "[ ]Range")) {
                llLRP(1,0);
                llSensorRepeat("",ToucherID,1,5.0,3.14159274,20.0);
                displayMenu();
            }
            else  if ((message == "Back")) {
                llMessageLinked(-4,1337,"DV_MAIN_MISC",ToucherID);
            }
            else  if ((~llListFindList(distance,((list)message)))) {
                llSensorRepeat("",ToucherID,1,5.0,3.14159274,((float)message));
                displayMenu();
            }
        }
    }

    
    link_message(integer sender,integer num,string str,key id) {
        if ((num == 1337)) {
            if ((str == llGetScriptName())) {
                llMessageLinked(-4,1338,llGetScriptName(),NULL_KEY);
                (ToucherID = id);
                displayMenu();
            }
        }
        if ((num == 1338)) {
            if ((str != llGetScriptName())) {
                llListenRemove(listen_id);
            }
        }
    }

  	
  	on_rez(integer num) {
        RequestPerms();
    }

  	
  	sensor(integer num_detected) {
    }

    
    no_sensor() {
        if ((llList2Integer(statesMenu,0) == 1)) {
            if ((llGetPermissions() & 16)) {
                llStartAnimation("shock");
                llSetTimerEvent(5.0);
            }
        }
    }

  	
  	timer() {
        llSetTimerEvent(0.0);
        llStopAnimation("shock");
    }
}
